
#include "mycoin.h"

myCoin::myCoin(QWidget *parent)
    : QPushButton{parent}
{

}

myCoin::myCoin(QString butimg)
{
    QPixmap pixmap;
    bool ret=pixmap.load(butimg);
    if(!ret){
        qDebug()<<butimg<<"加载图片失败";
    }
    this->setFixedSize(pixmap.size());
    this->setStyleSheet("QPushButton{border:0px}");
    this->setIcon(pixmap);
    this->setIconSize(pixmap.size());
    timer1=new QTimer(this);
    timer2=new QTimer(this);
    connect(timer1,&QTimer::timeout,this,[=](){
        QPixmap pixmap;
        QString str=QString(":/new/coifilp/res/Coin000%1.png").arg(this->min++);
        pixmap.load(str);
        this->setFixedSize(pixmap.size());
        this->setStyleSheet("QPushButton{border:0px;}");
        this->setIcon(pixmap);
        this->setIconSize(QSize(pixmap.size()));
        if(this->min>this->max)
        {
            this->min=1;
            isanimation=false;
            timer1->stop();
        }
        });
    connect(timer2,&QTimer::timeout,this,[=](){
        QPixmap pixmap;
        QString str=QString(":/new/coifilp/res/Coin000%1.png").arg(this->max--);
        pixmap.load(str);
        this->setFixedSize(pixmap.size());
        this->setStyleSheet("QPushButton{border:0px;}");
        this->setIcon(pixmap);
        this->setIconSize(QSize(pixmap.size()));
        if(this->max<this->min)
        {
            this->max=8;
            isanimation=false;
            timer2->stop();
        }
    });
}

void myCoin::ChangFlag()
{
    if(this->flag){

        timer1->start(30);
        isanimation=true;
        this->flag=false;
    }
    else{
        timer2->start(30);
        isanimation=true;
        this->flag=true;
    }
}

void myCoin::mousePressEvent(QMouseEvent *e)
{
    if(isanimation||isWin){
        return;
    }
    else{ QPushButton::mousePressEvent(e);}
}

